<?php
include_once("../includes/page_utf_class.php");
include_once("../module/product/includes/plugin_order_class.php");
include("../lang/cn/company_type_config.php");
include_once WEBROOT.'/module/inventory/config.inc.php';
$inventory_config = new config();
$order = new order;
//=======================
// if(isset($_GET['orderid'])&&is_numeric($_GET['orderid']))
// {
// 	$order->set_order_statu($_GET['orderid'],4,$_SESSION['ADMIN_USER']);
// 	msg("module.php?m=product&s=order.php");
// }
if($_GET['code'])
{
	$str=" and  a.order_id like '$_GET[code]%' ";
}
//----------------------分仓
$general_shop =$order->get_general_shop();

if ($general_shop!=0&&$general_shop!=$_GET['stock_shop']&&isset($_GET['stock_shop'])){
	msg('noright.php');
	exit;
}
if ($general_shop){
	$_GET['stock_shop'] =$general_shop;
}
if ($_GET['stock_shop']){
	$str.=" and stock_shop = '$_GET[stock_shop]' ";
}
//-----------------

if($_GET['shipping_id']>0){//配送方式
    $str.= " and shipping_id={$_GET['shipping_id']} ";
}


$str.=" and  a.status ='2' ";//待发货订单
// $sql="select * from ".ORDER."  where status=2 $str order by id desc";
/*
 * 判断不是admin管理员账号登录 就只能获取当前登录账号的数据
 */
if($_SESSION['ADMIN_USER']=='admin'){
	$sql="select a.member_id,a.order_type,a.status,a.print_status,a.order_id,a.client_system,a.client_platform,(cost+freight+tax_price+insurance_fee-cpns_price-discount) as sum,discount,cpns_price,cost,freight,tax_price,insurance_fee,(select username from ".MEMBER." where userid=a.member_id) user,(select name from ".MEMBER." where userid=a.member_id) nick_name,(select 1 from ".$inventory_config->db_prefix."orders where lotnumber =a.order_id and type=0 and timestocked=0 limit 1) is_stocked,ship_name,order_time,pay_time,ship_time,finished_time,pay_status,ship_status,shipping_name,shipping_express_name,payment_name,shipping_no from ".ORDER." a  where 1 $str having is_stocked is NULL order by a.order_time ";
}else{
	$user = $_SESSION['ADMIN_USER'];
	$asql = "select * from haiou_admin where user='$user'";
	$db->query($asql);
	$info = $db->fetchRow();
	$group_id = $info['group_id']; //分组id
	$asql = "select * from haiou_admin_group where group_id='$group_id'";
	$db->query($asql);
	$group_info = $db->fetchRow();
	if($group_info['group_name']=='商家'){
		$seller_id = $info['id'];
		$sql="select a.member_id,a.order_type,a.status,a.print_status,a.order_id,a.client_system,a.client_platform,(cost+freight+tax_price+insurance_fee-cpns_price-discount) as sum,discount,cpns_price,cost,freight,tax_price,insurance_fee,(select username from ".MEMBER." where userid=a.member_id) user,(select name from ".MEMBER." where userid=a.member_id) nick_name,(select 1 from ".$inventory_config->db_prefix."orders where lotnumber =a.order_id and type=0 and timestocked=0 limit 1) is_stocked,ship_name,order_time,pay_time,ship_time,finished_time,pay_status,ship_status,shipping_name,shipping_express_name,payment_name,shipping_no from ".ORDER." a  where a.seller_id=$seller_id $str having is_stocked is NULL order by a.order_time ";
	}else{
		$sql="select a.member_id,a.order_type,a.status,a.print_status,a.order_id,a.client_system,a.client_platform,(cost+freight+tax_price+insurance_fee-cpns_price-discount) as sum,discount,cpns_price,cost,freight,tax_price,insurance_fee,(select username from ".MEMBER." where userid=a.member_id) user,(select name from ".MEMBER." where userid=a.member_id) nick_name,(select 1 from ".$inventory_config->db_prefix."orders where lotnumber =a.order_id and type=0 and timestocked=0 limit 1) is_stocked,ship_name,order_time,pay_time,ship_time,finished_time,pay_status,ship_status,shipping_name,shipping_express_name,payment_name,shipping_no from ".ORDER." a  where 1 $str having is_stocked is NULL order by a.order_time ";
	}
}
//=============================
$page = new Page;
$page->listRows=20;
if (!$page->__get('totalRows')){
	$db->query($sql);
	$de['count']=$page->totalRows = $db->num_rows();
}
$de['count']=$de['count']?$de['count']:$_GET['totalRows'];
$sql .= "  limit ".$page->firstRow.",".$page->listRows;
$de['page'] = $page->prompt();
//=============================
$db->query($sql);
$ss=$db->getRows();
foreach($ss as $k)
{
	$k['order_ship_status']=$order_ship_status[$k['status']-1];
	$list[]=$k;
}
$de["list"]=$list;

//----------------------分仓
$stock_shops=$order->get_stock_shops();
$tpl->assign("stock_shops",$stock_shops);
$tpl->assign("general_shop",$general_shop);
//-----------------------------

/*****配送方式*****/
$sql = "select id,title from ".LGSTEMP." where status>0";
$db->query($sql);
$express_list = $db->getRows();
$tpl->assign("express_list",$express_list);
/*********/

$tpl->assign("order_shop_status",$order_shop_status);
$tpl->assign("de",$de);
$tpl->assign("config",$config);
$tpl->display("order_shipping.htm");

?>